package ace.module.captcha.sdk.core.feign.impl;

import ace.cmp.core.model.R;
import ace.cmp.openfeign.security.oauth2.core.config.FeignInternalServerOauth2SecurityConfig;
import ace.module.captcha.api.CaptchaImageApi;
import ace.module.captcha.api.model.dto.CaptchaImageDto;
import ace.module.captcha.api.model.input.CaptchaCreateInput;
import ace.module.captcha.sdk.core.constant.SdkConstant;
import ace.module.common.api.annotation.ApiRemoteProxyPriority;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 图形验证码.
 *
 * @author caspar
 */
@FeignClient(
    name = "${spring.cloud.openfeign.client.captchaImageFeign.name:" + SdkConstant.FEIGN_SERVICE_NAME + "}",
    contextId = "captchaImageFeign",
    path = CaptchaImageFeign.PATH,
    configuration = FeignInternalServerOauth2SecurityConfig.class,
    primary = false
)
@ApiRemoteProxyPriority
public interface CaptchaImageFeign extends CaptchaImageApi {

  String PATH = "${spring.cloud.openfeign.client.captchaImageFeign.path:/captcha/captcha-image/rpc}";

  @Operation(summary = "获取图形验证码", description = "base64Data格式")
  @PostMapping(path = "/create-base64-data")
  R<CaptchaImageDto> createBase64Data(@Valid @RequestBody CaptchaCreateInput captchaCreateInput);

  @Operation(summary = "验证图形验证码", description = "返回的data永远为null,code=0为成功，其它都是不成功")
  @GetMapping(path = "/verify")
  R<Void> verify(
      @Parameter(description = "验证码id", required = true)
      @Valid
      @NotNull
      @RequestParam("captchaItemId")
      Long captchaItemId,
      @Parameter(description = "验证码code", required = true) @Valid @NotEmpty @RequestParam("code")
      String code);
}
